package com.lbd.commons.interceptor;

import com.lbd.commons.ApplicationContextUtil;
import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by WangYajie on 2016/9/12.
 */

public class SessionInterceptor implements HandlerInterceptor {
    private final Logger log = Logger.getLogger(this.getClass());

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader("token");
        String dev = ApplicationContextUtil.applicationContext.getEnvironment().getProperty("dev");
        if ("true".equals(dev)) {
            log.info("正在以开发模式运行");
            return true;
        }
        log.info(token);
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws UnsupportedOperationException {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws UnsupportedOperationException {

    }
}
